<?php

defined('__EAPI_BASE') or define('__EAPI_BASE', dirname(__FILE__));

require_once 'api.database.php';
require_once 'api.user.php';
require_once 'api.xml.php';
require_once 'api.error.php';
require_once 'api.cache.php';
require_once 'api.char.php';
require_once 'api.char.mail.php';
require_once 'api.char.walletjournal.php';
require_once 'api.char.skilltraining.php';


/*try{
 }
 catch (Exception $e){
 echo 'Caught exception: ',  $e->getMessage(), "\n";
 //die ("Critical Error: Unable to initialize Session Class");
 }*/



class EAPIBase extends EAPIDatabase {

	protected $xml;
	protected $uObj;
	protected $character;
	protected $characterWalletJournal;
	protected $characterSkillTraining;
	protected $mail;

	public function __Construct($characterName, $apiUser, $apiKey){

		try{
			
			//construct the parent class
			parent::EAPIDatabase();
	
			//construct the EAPIUser object with credentials
			$this->uObj  = new EAPIUser($characterName, $apiUser, $apiKey);
	
			//construct the EAPIxml class using the apicore settings
			//$this->xml = new EAPIxml($this->apicore);
			$this->character = new EAPICharacter($this->apicore, $this->uObj);
			$this->characterWalletJournal = new EAPICharWalletJournal($this->apicore, $this->uObj);
			$this->characterSkillTraining = new EAPICharSkillTraining($this->apicore, $this->uObj);
			
			$this->mail = new EAPIMail($this->apicore, $this->uObj);
			
			if(empty($this->uObj) || empty($this->character)){
				
				throw new EAPIException('Could Not Initiate EAPIBase',602.1);
			}
		
		}catch (EAPIException $e){
			
			print $e;
			die();
			
		}

	}
	public function __Destruct(){}

/*	public function getEAPIUser(){

		//return the EAPIUser object
		return $this->uObj;
	}
*/
/*	public function getXML($path){

		return $this->xml->getXML($path,$this->uObj);
	}
*/	
	public function getCharData($type){
		return $this->character->getCharData($type);
	}

	public function getCharMail($offset=0,$limit=false){
		return $this->mail->getMail($offset,$limit);
	}
	
	public function getCharWalletJournal($offset=0,$limit=false){
		return $this->characterWalletJournal->getJournal($offset,$limit);
	}
	
	public function getCharSkillTraining(){
		return $this->characterSkillTraining->getSkillInTraining();
	}
};
?>